<SCRIPT language=JavaScript>
function reload(form){
var val=form.selMO.options[form.selMO.options.selectedIndex].value; 
self.location='6RC_1_MerchantDepositMO.php?selMO=' + val ;
}
</script>
<?php

require_once 'config.inc';
require('_db.inc');
require('_ui.inc');
//require('_bank.inc');
// Create a database connection
$conn = db_connect(MERCHANT_DB_USER, MERCHANT_DB_PASSWORD);

ui_print_header('Second Merchant - Deposit Money Order');
 echo <<<END
 <table width="800" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Merchant Deposit</strong></td>
</tr>
</table>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr><td width="190">Select a money order</td>
<td width="20">:</td>
<td>
END;

	$selMO=$_GET['selMO']; //This line is added to take care if your global variable is off
	
 	//get all money orders the merchant has
	$moneyOrders = db_do_query($conn,'SELECT * FROM MO_DETAIL_MERCHANTB where deposited=0');
	echo "<form method=post name=f1 action='6RC_1_MerchantDepositMO.php'>";
	echo "<select name='selMO' onchange=\"reload(this.form)\"><option value=''>Select one money order</option>";
	  foreach($moneyOrders as $MO) {
//	    	$moneyID = $MO['UNIQUENESS_STRING'];
//	    	$moneyVal = $MO['VAL'];
		if(($MO[UNIQUENESS_STRING].','.$MO[VERSION])==@$selMO){
			echo "<option selected value='$MO[UNIQUENESS_STRING],$MO[VERSION]'>$MO[UNIQUENESS_STRING]:$MO[VERSION]: $MO[VAL]</option>"."<BR>";}
		else{echo "<option value='$MO[UNIQUENESS_STRING],$MO[VERSION]'>$MO[UNIQUENESS_STRING]:$MO[VERSION]: $MO[VAL]</option>";}
		}
		echo "</select>";
		
	if(isset($selMO) and strlen($selMO) > 0){
		list($uniqStr, $version) = split(',', $selMO);
		$moneyOrder = db_do_query($conn,"SELECT * FROM MO_DETAIL_MERCHANTB where UNIQUENESS_STRING='" .$uniqStr ."' and VERSION=" .$version);
		 $selected_MO = $moneyOrder[0];
		// echo $selected_MO[VAL];
	}
 
 echo <<<END
 </form></td></tr>
<tr>
</table>
 </td></tr>
<tr>
<td><form name="form1" method="post" action="6RC_2_BankVerifyMO.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="150">Uniqueness String</td>
<td width="20">:</td>
<td><input name="unique_str" size="50" value="$selected_MO[UNIQUENESS_STRING]"></td>
</tr>
<tr>
<td>Money Amount</td>
<td>:</td>
<td><input name="val" size="50" value="$selected_MO[VAL]"></td>
</tr>
<tr>
<td>Money Order Version</td>
<td>:</td>
<td><input name="version" size="50" value="$selected_MO[VERSION]"></td>
</tr>
<tr>
<td>Bank Signature</td>
<td>:</td>
<td><textarea name="bank_sig" cols="50" rows="10" value="$selected_MO[BANK_SIG]">
END;
echo htmlentities($selected_MO[BANK_SIG]);
echo <<<END
</textarea></td>
</tr>
<tr>
<td>Selector String</td>
<td>:</td>
<td>
<input name="selector_str" size="50" value="$selected_MO[SELECTOR_STRING]"></td>
</tr>
<tr>
<td valign=top>ID String List</td>
<td>:</td>
<td>
END;

if (strlen($selected_MO[UNIQUENESS_STRING])>0){
	$IDs = db_do_query($conn,"SELECT * FROM MO_IDSTRINGS_MERCHANTB WHERE UNIQUENESS_STRING='" .$selected_MO[UNIQUENESS_STRING] ."' order by IDSTRING_N");
	  foreach($IDs as $IDstr) {
			echo "$IDstr[IDSTRING_N]. <input name='IDstr[" .$IDstr[IDSTRING_N] ."]' size='50' value='" . htmlentities($IDstr[ID_STRING]) ."' READONLY></br>";
		}
	
}
echo <<<END
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Deposit" value="Deposit"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
END;
ui_print_footer(date('Y-m-d H:i:s'));
oci_close($conn);
?>